package com.cdn.nodes.controller;

import javax.servlet.http.HttpServletResponse;

import com.cdn.common.core.utils.poi.ExcelUtil;
import com.cdn.nodes.domain.EdgeNodeScript;
import com.cdn.nodes.service.IEdgeNodeScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdn.common.log.annotation.Log;
import com.cdn.common.log.enums.BusinessType;
import com.cdn.common.security.annotation.RequiresPermissions;
import com.cdn.common.core.web.controller.BaseController;
import com.cdn.common.core.web.domain.AjaxResult;
import com.cdn.common.core.web.page.TableDataInfo;

import java.util.List;

/**
 * 初始化节点脚本Controller
 * 
 * @author Cinzia
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/script")
public class EdgeNodeScriptController extends BaseController
{
    @Autowired
    private IEdgeNodeScriptService edgeNodeScriptService;

    /**
     * 查询初始化节点脚本列表
     */
    @RequiresPermissions("node:script:list")
    @GetMapping("/list")
    public TableDataInfo list(EdgeNodeScript edgeNodeScript)
    {
        startPage();
        List<EdgeNodeScript> list = edgeNodeScriptService.selectEdgeNodeScriptList(edgeNodeScript);
        return getDataTable(list);
    }
//
//    /**
//     * 导出初始化节点脚本列表
//     */
//    @RequiresPermissions("node:script:export")
//    @Log(title = "初始化节点脚本", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, EdgeNodeScript edgeNodeScript)
//    {
//        List<EdgeNodeScript> list = edgeNodeScriptService.selectEdgeNodeScriptList(edgeNodeScript);
//        ExcelUtil<EdgeNodeScript> util = new ExcelUtil<EdgeNodeScript>(EdgeNodeScript.class);
//        util.exportExcel(response, list, "初始化节点脚本数据");
//    }

    /**
     * 获取初始化节点脚本详细信息
     */
    @RequiresPermissions("node:script:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(edgeNodeScriptService.selectEdgeNodeScriptById(id));
    }

    /**
     * 新增初始化节点脚本
     */
    @RequiresPermissions("node:script:add")
    @Log(title = "初始化节点脚本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EdgeNodeScript edgeNodeScript)
    {
        return toAjax(edgeNodeScriptService.insertEdgeNodeScript(edgeNodeScript));
    }

    /**
     * 修改初始化节点脚本
     */
    @RequiresPermissions("node:script:edit")
    @Log(title = "初始化节点脚本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EdgeNodeScript edgeNodeScript)
    {
        return toAjax(edgeNodeScriptService.updateEdgeNodeScript(edgeNodeScript));
    }

    /**
     * 删除初始化节点脚本
     */
    @RequiresPermissions("node:script:remove")
    @Log(title = "初始化节点脚本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(edgeNodeScriptService.deleteEdgeNodeScriptByIds(ids));
    }
}
